<?php

/**
 * 站内消息接口
 */
class BoardController extends ControllerBase {

    /**
     * 获取站内消息 [GET]
     * 接口请求地址：/board/get_messages/
     * @param int $pageno 第几页 默认0
     * @param int $pagesize 每页显示的数量 默认20
     * @example 返回结果：{"retcode":0,"retmsg":[{"id":1,"title":"这是一条站内消息1","content":"这是站内消息的内容1","mtime":"2015-11-18 21:22:32"},{"id":2,"title":"这是一条站内消息2","content":"这是站内消息的内容2","mtime":"2015-11-18 21:25:45"}]}
     */
    public function get_messagesAction() {
        $pageno = InputUtil::digitDefault($this->request->get('pageno'), 0);
        $pagesize = InputUtil::digitDefault($this->request->get('pagesize'), 20);
        $msg = Board::find([
            'id > 0',
            'limit' => [$pagesize, $pageno * $pagesize],
            'order' => 'id DESC'
        ]);
        if ($msg) {
            $msg = $msg->toArray();
        } else {
            $msg = [];
        }
        foreach ($msg as &$mg) {
            $mg['id'] = intval($mg['id']);
        }
        $this->echoMsg(0, $msg);
    }

}
